import { FormValidationResult, TableColumnCtx, TagProps } from "element-plus";
import { h } from "vue";
import { DataView } from "../components";

export type PageParams = {
  pageNum?: number,
  pageSize?: number
}

export type PageFetchAction<P, T> = (params: P & PageParams) => Promise<{ data: T[], total: number }>

export type OptionalMutable<T> = { -readonly [K in keyof T]?: T[K] }

export type TableColumnProps<T> = OptionalMutable<TableColumnCtx<T>> & {
  _k?: number,
  render?: (hFunc: typeof h, params: { $index: number, row: T, column: TableColumnProps<T> }) => ReturnType<typeof h>
  children?: TableColumnProps<T>[]
}

export type KeyValues<T> = { [k: string]: T }

export type DataViewInstance = InstanceType<typeof DataView>

export interface ModalForm {
  validate?: () => FormValidationResult | undefined,
  submit?: () => Promise<any>
}

export type SelectItem<T> = {
  value: T
  label: string
  type?: TagProps['type']
}
